package com.zzj.filedownloader.download.dbcontrol;

import android.os.Environment;
import java.io.File;
import java.io.IOException;
import java.util.List;
import net.lingala.zip4j.util.InternalZipConstants;

/* loaded from: classes.dex */
public class FileHelper {
    public static String baseFilePath = Environment.getExternalStorageDirectory().toString() + "/appResource/";
    private static String dowloadFilePath = null;
    private static String tempDirPath = null;
    private static String userID = "luffy";
    private static String[] wrongChars;

    static {
        String str = baseFilePath;
        dowloadFilePath = str;
        tempDirPath = str;
        wrongChars = new String[]{InternalZipConstants.ZIP_FILE_SEPARATOR, "\\", "*", "?", "<", ">", "\"", "|"};
    }

    public void newFile(File file) {
        if (file.exists()) {
            return;
        }
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void newDirFile(File file) {
        if (file.exists()) {
            return;
        }
        file.mkdirs();
    }

    public static double getSize(List<String> list) {
        double sizeUnitByte = getSizeUnitByte(list);
        Double.isNaN(sizeUnitByte);
        return sizeUnitByte / 1048576.0d;
    }

    public static long getSizeUnitByte(List<String> list) {
        long j = 0;
        for (int i = 0; i < list.size(); i++) {
            File file = new File(list.get(i));
            if (file.exists() && file.isFile()) {
                j += file.length();
            }
        }
        return j;
    }

    public static String getFileDefaultPath() {
        return dowloadFilePath;
    }

    public static String getTempDirPath() {
        return tempDirPath;
    }

    /* JADX WARN: Removed duplicated region for block: B:64:0x0066 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:71:0x0070 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public static boolean copyFile(java.lang.String r4, java.lang.String r5) {
        /*
            r0 = 0
            r1 = 0
            java.io.File r2 = new java.io.File     // Catch: java.lang.Throwable -> L4b java.lang.Exception -> L4e
            r2.<init>(r4)     // Catch: java.lang.Throwable -> L4b java.lang.Exception -> L4e
            boolean r2 = r2.exists()     // Catch: java.lang.Throwable -> L4b java.lang.Exception -> L4e
            if (r2 == 0) goto L35
            java.io.FileInputStream r2 = new java.io.FileInputStream     // Catch: java.lang.Throwable -> L4b java.lang.Exception -> L4e
            r2.<init>(r4)     // Catch: java.lang.Throwable -> L4b java.lang.Exception -> L4e
            java.io.FileOutputStream r4 = new java.io.FileOutputStream     // Catch: java.lang.Throwable -> L2d java.lang.Exception -> L31
            r4.<init>(r5)     // Catch: java.lang.Throwable -> L2d java.lang.Exception -> L31
            r5 = 1024(0x400, float:1.435E-42)
            byte[] r5 = new byte[r5]     // Catch: java.lang.Throwable -> L29 java.lang.Exception -> L2b
        L1b:
            int r0 = r2.read(r5)     // Catch: java.lang.Throwable -> L29 java.lang.Exception -> L2b
            r3 = -1
            if (r0 == r3) goto L26
            r4.write(r5, r1, r0)     // Catch: java.lang.Throwable -> L29 java.lang.Exception -> L2b
            goto L1b
        L26:
            r1 = 1
            r0 = r2
            goto L36
        L29:
            r5 = move-exception
            goto L2f
        L2b:
            r5 = move-exception
            goto L33
        L2d:
            r5 = move-exception
            r4 = r0
        L2f:
            r0 = r2
            goto L64
        L31:
            r5 = move-exception
            r4 = r0
        L33:
            r0 = r2
            goto L50
        L35:
            r4 = r0
        L36:
            if (r0 == 0) goto L40
            r0.close()     // Catch: java.io.IOException -> L3c
            goto L40
        L3c:
            r5 = move-exception
            r5.printStackTrace()
        L40:
            if (r4 == 0) goto L62
            r4.close()     // Catch: java.io.IOException -> L46
            goto L62
        L46:
            r4 = move-exception
            r4.printStackTrace()
            goto L62
        L4b:
            r5 = move-exception
            r4 = r0
            goto L64
        L4e:
            r5 = move-exception
            r4 = r0
        L50:
            r5.printStackTrace()     // Catch: java.lang.Throwable -> L63
            if (r0 == 0) goto L5d
            r0.close()     // Catch: java.io.IOException -> L59
            goto L5d
        L59:
            r5 = move-exception
            r5.printStackTrace()
        L5d:
            if (r4 == 0) goto L62
            r4.close()     // Catch: java.io.IOException -> L46
        L62:
            return r1
        L63:
            r5 = move-exception
        L64:
            if (r0 == 0) goto L6e
            r0.close()     // Catch: java.io.IOException -> L6a
            goto L6e
        L6a:
            r0 = move-exception
            r0.printStackTrace()
        L6e:
            if (r4 == 0) goto L78
            r4.close()     // Catch: java.io.IOException -> L74
            goto L78
        L74:
            r4 = move-exception
            r4.printStackTrace()
        L78:
            goto L7a
        L79:
            throw r5
        L7a:
            goto L79
        */
        throw new UnsupportedOperationException("Method not decompiled: com.zzj.filedownloader.download.dbcontrol.FileHelper.copyFile(java.lang.String, java.lang.String):boolean");
    }

    public static String getUserID() {
        return userID;
    }

    public static String filterIDChars(String str) {
        if (str != null) {
            int i = 0;
            while (true) {
                String[] strArr = wrongChars;
                if (i >= strArr.length) {
                    break;
                }
                String str2 = strArr[i];
                if (str.contains(str2)) {
                    str = str.replaceAll(str2, "");
                }
                i++;
            }
        }
        return str;
    }

    public static String getFilterFileName(String str) {
        int i;
        int length;
        if (str == null || "".equals(str)) {
            return str;
        }
        boolean startsWith = str.startsWith("(");
        int indexOf = str.indexOf(")");
        return (!startsWith || indexOf == -1 || (i = indexOf + 1) >= (length = str.length())) ? str : str.substring(i, length);
    }
}
